 <!DOCTYPE html>
 
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.Date" %> 
<%@ page import="java.text.DateFormat" %> 
<%@ page import="java.text.SimpleDateFormat" %> 


<% 
try {
	
	String connectionURL = "jdbc:mysql://localhost:3306/unilearn"; 
	
	int c_row_count = 0;
	Connection connection = null;
	Statement stmt = null;
	ResultSet rst=null;

	Class.forName("com.mysql.jdbc.Driver").newInstance(); 

	connection = DriverManager.getConnection(connectionURL, "root", "");
	stmt = connection.createStatement();
	
	if(!connection.isClosed())
	{
		
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
		Date _now = new Date();
		
		
		//get session values
		String user_id = (String)session.getAttribute("UserID");
		String permission = (String)session.getAttribute("Permission");
		String first_name = (String)session.getAttribute("LastName");
		String last_name = (String)session.getAttribute("FirstName");
		
		//String subject_id = request.getParameter("datSubjectID");
		//String subject_code = request.getParameter("datSubjectCode");
		//String subject_name = request.getParameter("datSubjectName");
	
%>

<html lang="en">
<head>
<script type="text/javascript">
	function linkToAssCreate(subject_id)
	{
		window.location="assignmentCreate.jsp?SubjectID=" + subject_id;
	}
</script>
<link rel="stylesheet" type="text/css" href="common.css">
<title>UniLearn System</title>
</head>
<body>
<form action="" method="post" name="entry" onSubmit="return validate(this)">
<table class="TblBody" style="width:720px">
	<tr>
		<td>
			<div class="contentb">
				<table width="100%">
                    <tr>
						<%
							String subject_id = request.getParameter("datSubjectID");
						%>
                        <td style="background-color:#ccff99; font-size:20px; font-weight:bold; height:30px">Assignment List</td>
						
                    </tr>
					<tr>
                        <td>
							<table class="SubTable">
								<tr>
									<th>Assignment</th>
									<th>Status</th>
									<th>Due Date</th>
									<th></th>
								</tr>
							<%
								rst = stmt.executeQuery("SELECT * FROM assignment WHERE subject_id = " + subject_id);
								
								while(rst.next())
								{
								%>
									<tr>
										<td><a><%= rst.getString("assignment_name")%></a></td>
										<td>
											<%
												String ass_id = rst.getString("assignment_id");
												String ass_status = rst.getString("assignment_status");
												int int_ass_status = Integer.parseInt(ass_status);
												
												if(int_ass_status == 1){
											%>
												Open
											<%
												}else{
											%>
												Close
											<%
												}
											%>
										</td>
										<td><a><%= dateFormat2.format(dateFormat2.parse(rst.getString("end_date").toString()))%></a></td>
										<td>
											<a href="assignmentUpdate.jsp?AssignmentID=<%= ass_id %>">Update</a>
										</td>
										
									</tr>
								<%
								}
							%>
							</table>
							<input type="button" value="Create New" style="width:150px" onClick="linkToAssCreate(<%=request.getParameter("datSubjectID")%>)" name="btnCreateNew" />
                        </td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
</table>
</form>
<%
}
	}catch(Exception ex){

		out.println(ex);
	}
%>
</body>
</html>